import 'package:flutter/material.dart';

class Exam_9 extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("进度指示器"),
      ),
      body: Content(),
    );
  }

}

class Content extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Column(
      children: <Widget>[
        /** 模糊进度条，会执行一个动画*/
        LinearProgressIndicator(
          backgroundColor: Colors.grey[200],
          valueColor: AlwaysStoppedAnimation(Colors.redAccent),
        ),

        /** 进度条显示50%*/
        LinearProgressIndicator(
          backgroundColor: Colors.grey[200],
          valueColor: AlwaysStoppedAnimation(Colors.blue),
          value: .5,
        ),

        /**圆形进度条,旋转动画*/
        CircularProgressIndicator(
          backgroundColor: Colors.grey[200],
          valueColor: AlwaysStoppedAnimation(Colors.redAccent),
        ),
        /**圆形进度条*/
        CircularProgressIndicator(
          backgroundColor: Colors.grey[200],
          valueColor: AlwaysStoppedAnimation(Colors.orange),
          value: .5,
        ),
        /**指定尺寸,线性进度条*/
        SizedBox(
          height: 30,
          child: LinearProgressIndicator(
            backgroundColor: Colors.grey[200],
            valueColor: AlwaysStoppedAnimation(Colors.blue),
            value: .5,
          ),
        ),

        /**指定圆形进度条尺寸*/
        SizedBox(
          width: 100,
          height: 100,
          child: CircularProgressIndicator(
            backgroundColor: Colors.grey[200],
            valueColor: AlwaysStoppedAnimation(Colors.black),
            value: .8,
          ),
        ),

        /**进度色动画组件*/
        ProgressRoute(),
      ],

    );
  }

}

/**进度色动画组件*/
class ProgressRoute extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _ProgressRouteState();
  }
}

class _ProgressRouteState extends State<ProgressRoute> with SingleTickerProviderStateMixin{

  AnimationController _animationController;

  @override
  void initState() {
   //动画执行3秒
    _animationController = new AnimationController(vsync: this,duration: Duration(seconds: 3));
    _animationController.forward();
    _animationController.addListener(()=> setState(()=>{

    }) );
    super.initState();
  }

  @override
  void didUpdateWidget(ProgressRoute oldWidget) {
    _animationController.dispose();
    super.didUpdateWidget(oldWidget);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return SingleChildScrollView(
      child: Column(
        children: <Widget>[
          Padding(
            padding: EdgeInsets.all(16),
            child: LinearProgressIndicator(
              backgroundColor: Colors.grey[200],
              valueColor: ColorTween(begin: Colors.grey,end: Colors.blue).animate(_animationController),
              value: _animationController.value,
            ),
          )
        ],
      ),
    );
  }

}